﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "CmdInplaceEditNameDefines.h"
#include "GmUiInplaceEditCommandRegister.h"
#include "ActionPickInplaceEditOrigin.h"

// 平台头文件
#include "GbmpCommandBase.h"
#include "IUiDocument.h"
#include "IUiView.h"

#include "ISelection.h"
#include "IGraphicsNodeReference.h"
#include "UiCommonDialog.h"
#include "IModelView.h"
#include "GbmpModelViewTypes.h"
#include "UiDocumentViewUtils.h"
#include "CmdStatusUtils.h"
#include "GbmpUiPlatformCommandIds.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;

// 这是个给开发人员临时使用的命令
class CmdEnterInplaceCreateMode : public GbmpCommandBase
{
public:
    CmdEnterInplaceCreateMode()
        : GbmpCommandBase(ID_CMD_ENTER_INPLACE_CREATE_MODE, true)
    {}

    // 实现ICommand接口
public:
    virtual OwnerPtr<IAction> ExecuteCommand(const gcmp::CommandParameters& cmdParams) override;
    virtual bool IsEnabled() const override { CMD_ONLY_ENABLE_IN_PROJECT_ENVIRONMENT }
    virtual bool IsVisible() const override { CMD_ONLY_VISIBLE_IN_PROJECT_ENVIRONMENT }

protected:
    // 命令执行前清空选择集
    virtual bool ShouldClearSelectionBeforeExecution() const override { return true; }
};

OwnerPtr<IAction> CmdEnterInplaceCreateMode::ExecuteCommand(const gcmp::CommandParameters& cmdParams)
{
    IDocument* pDoc = UiDocumentViewUtils::GetCurrentDocument();
    if (!pDoc)
    {
        return nullptr;
    }

    // 不支持在立面视图启动在位创建
    IModelView* pModelView = UiDocumentViewUtils::GetCurrentModelView();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pModelView, L"pModelView为空",L"GDMPLab",L"2024-03-30");
    const std::wstring& viewType = pModelView->GetUserDataId();

    if (PlanViewType != viewType && View3DViewType != viewType)
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"在位创建"), GBMP_TR(L"此视图下不支持在位创建构件"), (int)UiCommonDialog::ButtonType::OK);
        return nullptr;
    }

    return NEW_AS_OWNER_PTR(ActionPickInplaceEditOrigin);
}

REGISTER_GM_COMMAND(CmdEnterInplaceCreateMode)
